

import 'package:WebTest/chooseFood/core/model/category_model.dart';
import 'package:WebTest/chooseFood/core/model/meal_model.dart';
import 'package:WebTest/chooseFood/core/viewModel/meal_view_model.dart';
import 'package:WebTest/chooseFood/ui/widgets/meal_item.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';


class BDMealContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final mealModel = ModalRoute.of(context).settings.arguments as BDCategoryModel;
    return Selector<BDMealViewModel,List<BDMealModel>>(
      selector: (context,mealVM) => mealVM.meals.where((meal)=> meal.categories.contains(mealModel.id)).toList(),
      shouldRebuild: (prev,next) => !ListEquality().equals(prev,next),
      builder: (context,meals,child){
        return ListView.builder(
          itemCount: meals.length,
          itemBuilder: (context,index){
            return BDMealItem(meals[index]);
          },
        );
      },
    );
  }
}


//class BDMealContent extends StatelessWidget {
//  @override
//  Widget build(BuildContext context) {
//    final mealModel = ModalRoute.of(context).settings.arguments as BDCategoryModel;
//    return Consumer<BDMealViewModel>(
//      builder: (context,mealVM,child){
//        final meals = mealVM.meals.where((meal)=> meal.categories.contains(mealModel.id)).toList();
//        return ListView.builder(
//          itemCount: meals.length,
//          itemBuilder: (context,index){
//            return ListTile(title: Text(meals[index].title),);
//          },
//        );
//      },
//    );
//  }
//}